<template>
	<!-- 顶部导航 -->
	<div class="topbox">
		<div class="topbox-left">
			<div class="topbox-left-logo">
				<el-image class="icon" src="/src/assets/images/index/logo.png" fit="contain"></el-image>
			</div>
			<div>首页</div>
			<div>文章</div>
			<div>日常</div>
			<div>留言板</div>
			<div>关于</div>
		</div>
		<div class="topbox-center">
			<div>更多</div>
			<div>首页</div>
			<div>搜索</div>
		</div>
		<div class="topbox-right">
			<el-image class="icon" src="/src/assets/images/index/search.png" fit="cover"></el-image>
		</div>
	</div>
</template>

<script>
	export default {
		name: "wuNav",
		props: {
			content: "", //接收参数
		},
		data() {
			return {};
		},
		mounted() {
			// 监听页面滚动事件
			window.addEventListener('scroll', this.handleScroll);
		},
		beforeDestroy() {
			// 组件销毁前移除事件监听器
			window.removeEventListener('scroll', this.handleScroll);
		},
		methods: {
			handleScroll() {
				var scrollDistance = window.pageYOffset || document.documentElement.scrollTop;
				var topbox = document.querySelector('.topbox');

				// 设置一个阈值，当滚动距离超过这个值时，应用 transform: translateY(-100px)
				if (scrollDistance > 300) {
					topbox.style.transform = 'translateY(-80px)';
				} else {
					topbox.style.transform = 'translateY(0)';
				}
			}
		}
	}
</script>

<style lang="scss">
	.topbox {
		width: 80%;
		height: 80px;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 999;
		transition: all 0.3s ease;
	}

	.topbox-left {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex: 1;
		font-size: 1.25em;
	}


	.topbox-left>div:hover {
		color: rgba(255, 255, 255, .65);
		cursor: pointer;
		transition: color 0.2s ease-in-out;
	}

	.icon {
		width: 36px;
		height: 36px;
	}

	.topbox-left-logo {
		display: flex;
		align-items: center;
		justify-content: flex-start;
	}

	.topbox-center {
		width: 100%;
		font-size: 1.25em;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.topbox-right {
		width: 50%;
		display: flex;
		align-items: center;
		justify-content: end;
	}
</style>